package yxy.game.pm2.command.camptower;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.CampTowerMessage;
import yxy.game.pm2.module.battle.BattleType;
import yxy.game.pm2.module.camptower.CampTowerHandle;

/**
 * 阶段目标奖励领奖
 *
 * @ClassName CMD_CampTowerStageTargetReceive
 * @Author jingtao-zheng
 * @Date 2022/8/5 14:17
 * @Version 1.0
 **/
@MessageType(proto = Command.CampTowerStageTargetReceive, classtype = CampTowerMessage.CampTowerStageTargetReceiveRequest.class)
public class CMD_CampTowerStageTargetReceive extends Command<CampTowerMessage.CampTowerStageTargetReceiveRequest> {
    @Override
    public void execute(MessageSource messageSource, CampTowerMessage.CampTowerStageTargetReceiveRequest request) throws Exception {
        String playerCode = messageSource.getTag();
        //获取阵营塔类型
        int type = request.getType().getNumber();
        //领奖id
        int box = request.getBox();
        CampTowerMessage.CampTowerStageTargetReceiveResponse.Builder response = CampTowerMessage.CampTowerStageTargetReceiveResponse.newBuilder();
        BattleType battleType = CampTowerHandle.matchBattleType(type);
        Result result = new CampTowerHandle(battleType).levelReward(playerCode, box, response, type);

        send(messageSource, response, result);
    }

    private void send(MessageSource messageSource, CampTowerMessage.CampTowerStageTargetReceiveResponse.Builder response, Result result) {
        response.setResult(result.packResult());
        MessageEmitterHandler.getInstance().send(messageSource, response.build());
    }
}
